package com.ek.kademlia;

import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;

import com.ek.common.Observable;

public class ObservableLinkedList<T extends Observable> extends LinkedList<T> {
    private static final long serialVersionUID = -148788192403994042L;

    public ObservableLinkedList() {
        super();
    }

    public ObservableLinkedList(Collection<T> coll) {
        super(coll);
    }

    public T getFirstNotSeen() {
        T first = getFirst();
        if (!first.alreadySeen()) {
            return first;
        } else {
            for (Iterator<T> iterator = iterator(); iterator.hasNext();) {
                T next = iterator.next();
                if (!next.alreadySeen()) {
                    return next;
                }
            }
        }
        return null;
    }

    public void addAllIfNotContained(Collection<T> list) {
        for (T observable : list) {
            if (!contains(observable)) {
                add(observable);
            }
        }
    }
}
